package AndroidProjectFile

import xml.{PrettyPrinter, XML}
import FilesGenerator.FileManager
import xml.NodeSeq._

/**
 * Created by IntelliJ IDEA.
 * User: SDi
 * Date: 12.04.11
 * Time: 14:18
 * To change this template use File | Settings | File Templates.
 */

object MarketKey {

  val filePath = "configs/MarketKey.sdpm"

  var path = ""
  var alias = ""
  var aliasPass = ""
  var storePass = ""

  def exists(): Boolean = new java.io.File(filePath).exists()

  def load {
    val file = XML.loadFile(filePath)
    path = (file \\ "keyPath" \ "@value") text;
    alias = (file \\ "keyAlias" \ "@value") text;
    aliasPass = (file \\ "keyAliasPass" \ "@value") text;
    storePass = (file \\ "keyStorePass" \ "@value") text;
  }

  def save(): Unit = {

    var config =
      <configs>
          <keyPath value={path}/>
          <keyAlias value={alias}/>
          <keyAliasPass value={aliasPass}/>
          <keyStorePass value={storePass}/>
      </configs>

    XML.save(FileManager.createFile(filePath), XML.loadString(new PrettyPrinter(80, 3).format(config)), "UTF-8", true, null)
  }
}